package com.ruoyi.house_sale.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.HouseEvent;
import com.ruoyi.house_sale.service.IHouseEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房产事件Controller
 *
 * @author ruoyi
 * @date 2022-04-22
 */
@RestController
@RequestMapping("/house_sale/HouseEvent")
public class HouseEventController extends BaseController
{
    @Autowired
    private IHouseEventService houseEventService;

    /**
     * 查询房产事件列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:HouseEvent:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseEvent houseEvent)
    {
        startPage();
        List<HouseEvent> list = houseEventService.selectHouseEventList(houseEvent);
        return getDataTable(list);
    }

    /**
     * 导出房产事件列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:HouseEvent:export')")
    @Log(title = "房产事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseEvent houseEvent)
    {
        List<HouseEvent> list = houseEventService.selectHouseEventList(houseEvent);
        ExcelUtil<HouseEvent> util = new ExcelUtil<HouseEvent>(HouseEvent.class);
        util.exportExcel(response, list, "房产事件数据");
    }

    /**
     * 获取房产事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:HouseEvent:query')")
    @GetMapping(value = "/{houseeventid}")
    public AjaxResult getInfo(@PathVariable("houseeventid") Long houseeventid)
    {
        return AjaxResult.success(houseEventService.selectHouseEventByHouseeventid(houseeventid));
    }

    /**
     * 新增房产事件
     */
    @PreAuthorize("@ss.hasPermi('house_sale:HouseEvent:add')")
    @Log(title = "房产事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseEvent houseEvent)
    {
        houseEvent.setOprtime(new Date());
        return toAjax(houseEventService.insertHouseEvent(houseEvent));
    }

    /**
     * 修改房产事件
     */
    @PreAuthorize("@ss.hasPermi('house_sale:HouseEvent:edit')")
    @Log(title = "房产事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseEvent houseEvent)
    {
        return toAjax(houseEventService.updateHouseEvent(houseEvent));
    }

    /**
     * 删除房产事件
     */
    @PreAuthorize("@ss.hasPermi('house_sale:HouseEvent:remove')")
    @Log(title = "房产事件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{houseeventids}")
    public AjaxResult remove(@PathVariable Long[] houseeventids)
    {
        return toAjax(houseEventService.deleteHouseEventByHouseeventids(houseeventids));
    }
}
